<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools 1.3 Documentation - Types/Number.Format</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Number">Number</a></h4>
      <div class="menu-item"><a href="#Number:format">format</a></div>
      <div class="menu-item"><a href="#Number:formatCurrency">formatCurrency</a></div>
      <div class="menu-item"><a href="#Number:formatPercentage">formatPercentage</a></div>
    </div>
    <div class="l-border r-border span-15 content">
      <h1 id="Number"><a href="#Number">Type: Number</a></h1>
      <p class="description">A collection of useful methods to format Numbers.</p>
      <h3>See Also</h3>
      <ul>
        <li><a href="../../../docs/core/Types/Number.html">Number</a></li>
        <li><a href="../../../docs/more/Locale/Number.html">Number Locale</a></li>
      </ul>
      <h2 id="Number:format"><a href="#Number:format">Number Method: format</a></h2>
      <p class="description">Formats a number into a formatted string for display to user. It respects localization.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myNumber.<span class="me1">format</span><span class="br0">(</span><span class="br0">[</span>options<span class="br0">]</span><span class="br0">)</span>;

</pre>
      <h3>Arguments</h3>
      <ol>
        <li>options - (<em>object</em>, optional) Optional configuration values:
          <ul>
            <li>decimal - (<em>string</em>) Decimal separator</li>
            <li>group - (<em>string</em>) Thousands separator</li>
            <li>decimals - (<em>number</em>) Number of decimals</li>
            <li>precision - (<em>number</em>) Number of significant numbers</li>
            <li>scientific - (<em>boolean</em>) Set to <code>false</code> if the 1.4e+4 should be replaced by 1400</li>
            <li>suffix - (<em>string</em>) String prepended after the number</li>
            <li>suffix - (<em>string</em>) String appended after the number</li>
          </ul>
        </li>
      </ol>
      <h3>Examples</h3>
      <pre class="javascript"><span class="br0">(</span><span class="nu0">123123123.176</span><span class="br0">)</span>.<span class="me1">format</span><span class="br0">(</span><span class="br0">{</span>

    decimal: <span class="st0">"."</span>,
    group: <span class="st0">","</span>,
    decimals: <span class="nu0">2</span>,
    prefix: <span class="st0">"&amp;amp;#165;"</span>,
    suffix: <span class="st0">" (YEN)"</span>
<span class="br0">}</span><span class="br0">)</span><span class="br0">)</span>; <span class="co1">// returns "&amp;#165;123.123.123,18 (YEN)"</span>

&nbsp;
<span class="br0">(</span><span class="nu0">123456789</span><span class="br0">)</span>.<span class="me1">format</span><span class="br0">(</span><span class="br0">{</span>
    precision: <span class="nu0">4</span>,
    scientific: <span class="kw2">false</span>
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// 123,500,000</span>

</pre>
      <h3>Returns</h3>
      <ul>
        <li>(<em>string</em>) the formatted number</li>
      </ul>
      <h2 id="Number:formatCurrency"><a href="#Number:formatCurrency">Number Method: formatCurrency</a></h2>
      <p class="description">Formats a number as currency, with respect to localization.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myNumber.<span class="me1">formatCurrency</span><span class="br0">(</span><span class="br0">)</span>;
</pre>
      <h3>Example</h3>
      <pre class="javascript"><span class="kw2">var</span> money = <span class="br0">(</span><span class="nu0">4125.957</span><span class="br0">)</span>.<span class="me1">formatCurrency</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// $ 4,125.96</span>

</pre>
      <h3>Returns</h3>
      <ul>
        <li>(<em>string</em>) the formatted number</li>
      </ul>
      <h2 id="Number:formatPercentage"><a href="#Number:formatPercentage">Number Method: formatPercentage</a></h2>
      <p class="description">Formats a number as a percentage.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myNumber.<span class="me1">formatPercentage</span><span class="br0">(</span><span class="br0">)</span>;
</pre>
      <h3>Example</h3>
      <pre class="javascript"><span class="kw2">var</span> percentage = <span class="br0">(</span><span class="nu0">4125.957</span><span class="br0">)</span>.<span class="me1">formatPercentage</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// 4,125.96%</span>

</pre>
      <h3>Returns</h3>
      <ul>
        <li>(<em>string</em>) the formatted percentage</li>
      </ul>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
